package com.ruoyi.web.controller.zhuangxiucontroller.orderformController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.customer.CustomerLogin;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderCart;
import com.ruoyi.system.service.zhaungxiuservice.shopService.IOrderCartService;
import com.ruoyi.system.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.Data;
import java.lang.reflect.Parameter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping(value = "/api/shop/product")
public class OrderShoppingController extends BaseController {

    @Autowired
    private IOrderCartService orderCartService;
    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private HttpServletRequest request;

        //前台查询购物车列表
    @RequestMapping(value = "/getShopping",method = RequestMethod.GET)
    private List<OrderCart> getShopping(OrderCart orderCart){
        CustomerLogin loginCustomer = tokenUtils.getLoginCustomer(request);
        orderCart.setCustomerId(Integer.parseInt(loginCustomer.getCustomerId().toString()));
        List<OrderCart> orderCarts = orderCartService.selectOrderCartList(orderCart);
        System.out.println(orderCarts);
        return orderCarts;
    }
    //添加购物车
    @RequestMapping(value = "/saveShopping",method = RequestMethod.POST)
    private int saveShopping(@RequestBody  OrderCart orderCart){
        CustomerLogin loginCustomer = tokenUtils.getLoginCustomer(request);
        orderCart.setCustomerId(Integer.parseInt(loginCustomer.getCustomerId().toString())); //用户id
        Date data = new Date();    //获取添加时间
        orderCart.setAddTime(data);
        System.out.println(orderCart);
        return orderCartService.insertOrderCart(orderCart);
    }
}
